import React, { PureComponent } from 'react';
import { NavBar, Icon,Modal } from 'antd-mobile';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';

import { nav_top_bar } from './NavTopBar.less';

class NavTopBar extends PureComponent {


    render() {
        const { dispatch, title='', leftContent=[], rightContent=[], noBack = false, isBlack = false, jumpUrl = "", onEnter = false, ...othersProps } = this.props;
        return (
            <NavBar
                {...othersProps}
                className={ nav_top_bar }
                mode="dark"
                icon={ noBack ? "" : <Icon style={{ width:'0.7rem', height:'0.7rem', verticalAlign:"middle" }} type="left" /> }
                onLeftClick={() => {
                    console.log(isBlack,jumpUrl)
                    if (noBack) return false;
                    else if (isBlack) return dispatch(routerRedux.replace({pathname: jumpUrl}));
                    else if (onEnter) {
                         Modal.alert('',<div style={{ lineHeight: '0.9rem', fontSize: "0.3rem",padding:".5rem",color:"#333" }}> 您确定要离开吗？</div>, [
                          { text: '取消', onPress: () => console.log('cancel') },
                          {
                            text: '确认离开',
                            onPress: () => dispatch(routerRedux.goBack())
                              // new Promise((resolve) => {
                              //   Toast.info('onPress Promise', 1);
                              //   setTimeout(resolve, 1000);
                              // }),
                          },
                        ])
                    }
                    else dispatch(routerRedux.goBack());
                }}
                rightContent={rightContent}>
                {title}
            </NavBar>
        );
    }
}

export default NavTopBar;

/*
 * 头部导航
 * */
